package com.yunfeisoft.business.dao.impl.postgres;

import com.applet.base.ServiceDaoImpl;
import com.applet.sql.builder.WhereBuilder;
import com.applet.utils.Page;
import com.yunfeisoft.business.dao.inter.SmsCouponHistoryDao;
import com.yunfeisoft.business.model.SmsCouponHistory;
import org.springframework.stereotype.Repository;
import org.springframework.util.ObjectUtils;

import java.util.List;
import java.util.Map;

/**
 * ClassName: SmsCouponHistoryDaoImpl
 * Description: 优惠券使用、领取历史表Dao实现
 * Author: Jackie liu
 * Date: 2020-06-02
 */
@Repository
public class SmsCouponHistoryDaoImpl extends ServiceDaoImpl<SmsCouponHistory, String> implements SmsCouponHistoryDao {

    @Override
    public Page<SmsCouponHistory> queryPage(Map<String, Object> params) {
        WhereBuilder wb = new WhereBuilder();
        if (params != null) {
            if (!ObjectUtils.isEmpty(params.get("ordersn"))) {
                wb.andFullLike("orderId", params.get("ordersn"));
            }
            if (!ObjectUtils.isEmpty(params.get("couponId"))) {
                wb.andEquals("couponId", params.get("couponId"));
            }
            initPageParam(wb, params);
        }
        return queryPage(wb);
    }

    /**
     * 查询优惠券使用历史记录
     * @param couponId
     * @return
     */
    @Override
    public List<SmsCouponHistory> queryByCouponId(String couponId) {
        WhereBuilder wb = new WhereBuilder();
        wb.andEquals("couponId", couponId);
        return query(wb);
    }
}